
package net.tycmc.cty.ctyms.timejob.iems.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.bulb.dbutil.global.GlobalDBVar;
import net.tycmc.cty.ctyms.timejob.common.DateRegUtil;
import net.tycmc.cty.ctyms.timejob.common.DynamicReadConfig;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSDAO;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSTransDAO;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;


public class MtnForstNewConn {
	private static Logger logdata = Logger.getLogger("mtnForstLog");
	IBaseDAO baseDAO;
	private ITransactionDAO tranDAO;
	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}


	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}


	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}


	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}


	/**
	 * 车辆定时预测保养计划方法
	 * 
	 */
	public boolean mtnForstNewShowTime() {
		
		try {
			System.out.println("保养预测开始~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			//查询保存了保养标准的设备型号下的所有设备
			List<Map<String,Object>> VehicleInfoList = this.getVehicleInfoListByStandard();
			  Calendar calBegin = Calendar.getInstance();
			  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			  List DataList = new ArrayList();
			  Calendar calToday = Calendar.getInstance();
			  DataList.add(sdf.format(calToday.getTime()));
			//获取包括今天在内的未来30天的日期列表
			for(int i = 1;i<30;i++){
				 calBegin.add(Calendar.DAY_OF_MONTH, 1);
				 DataList.add(sdf.format(calBegin.getTime()));
			}
			//获取昨天的日期
			 Calendar calYesDay = Calendar.getInstance();
			 calYesDay.add(Calendar.DAY_OF_MONTH, -1);
			 String yesDate = sdf.format(calYesDay.getTime());
			 //获取从昨天至前30天日期 
			 Calendar calYesDayTh = Calendar.getInstance();
			 calYesDayTh.add(Calendar.DAY_OF_MONTH, -31);
			 String yesDateTh = sdf.format(calYesDayTh.getTime());
			
			//二期优化：是否需要备份数据
			String isbakTable="";
			try {
				isbakTable = DynamicReadConfig.getConfigProperty("config.properties", "MtnFrostNew");
			} catch (ConfigurationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(!StringUtil.isValid(isbakTable)){
				isbakTable = "0";
			}
			
			//初始化保养预测信息表
			boolean ok = initMtnFrost(DataList);
			//执行成功
			if(ok){
				//获取系统配置的保养参数信息
				Map<String,Object> sysParamMap = this.getSys_ParmConfig();
				//获取每台设备前30天内平均行驶里程
				Map<String,Object> vehiclePerDayMileMap = this.getPerDayMile(VehicleInfoList,yesDate,yesDateTh,sysParamMap);
				//获取每台设备前30天内平均工作小时数
				Map<String,Object> vehiclePerDayWorkHourMap = this.getPerDayWorkHour(VehicleInfoList,yesDate,yesDateTh,sysParamMap);
				//获取设定了固定时间间隔保养方式的设备最近一次的提醒日期
				Map<String,Object> vehicleTipDateMap = this.getvehicleTipDateLast(VehicleInfoList);
				//获取设定了保养标准的设备的全部信息集合
				List<Map<String,Object>> VehicleAllInfoList = this.getVehicleAllInfoList(yesDate);
				
				try{if(VehicleAllInfoList!=null && VehicleAllInfoList.size()>0){
					for(int i = 0;i<VehicleAllInfoList.size();i++){
						//预测保养方式为--公里数
						if("2".equals(MapGetter.getString(VehicleAllInfoList.get(i), "MtnFS_MtnType"))){
							this.frostByKm(VehicleAllInfoList.get(i),vehiclePerDayMileMap,DataList);
						//预测保养方式为--工作小时数
						}else if("1".equals(MapGetter.getString(VehicleAllInfoList.get(i), "MtnFS_MtnType"))){
							this.frostByWorkHour(VehicleAllInfoList.get(i),vehiclePerDayWorkHourMap,DataList);
						//预测保养方式为--固定时间间隔
						}else if("3".equals(MapGetter.getString(VehicleAllInfoList.get(i), "MtnFS_MtnType"))){
							//判断是否设置了固定时间间隔开始日期
							if(StringUtil.isValid(MapGetter.getString(VehicleAllInfoList.get(i), "MaintfixeStartDate"))){
								this.frostByDate(VehicleAllInfoList.get(i),vehicleTipDateMap,DataList);
							}
							
						}
					}
					MyConnectDSDAO myConnectDSDAO=new MyConnectDSDAO();
					int in=0;
					//循环执行完毕，清空预测信息表
					String sqlInfo = "truncate table MtnForst_InfoNew";
					myConnectDSDAO.execUpdate(sqlInfo, new Object[]{});

					//将临时表数据全部插入预测信息表
					String insertSql = "insert into MtnForst_InfoNew " +
					"(MtnFN_MsgTime,MtnFN_VclID,MtnFN_VclT_ID,MtnFN_DatePre,MtnFN_IsKmForst," +
					"MtnFN_IsWorkForst,MtnFN_IsGapForst,MtnFN_KmPre,MtnFN_WorkPre,MtnFN_GapPre)" +
					"select  MtnFN_MsgTime,MtnFN_VclID,MtnFN_VclT_ID,MtnFN_DatePre,MtnFN_IsKmForst," +
					"MtnFN_IsWorkForst,MtnFN_IsGapForst,MtnFN_KmPre,MtnFN_WorkPre,MtnFN_GapPre " +
					"from MtnForst_InfoNew_Tmp";
					
					try{
						int isOk = myConnectDSDAO.execInsert(insertSql, new Object[]{});
						if(isOk>0){
							//执行成功，清空临时表
							String sqlInfoTmp = "truncate table MtnForst_InfoNew_Tmp";
							myConnectDSDAO.execUpdate(sqlInfoTmp, new Object[]{});
							//二期优化：是否需要数据备份
							if(isbakTable.equals("1")){
								MyConnectDSDAO conn = new MyConnectDSDAO(true);
								in =conn.execUpdate(sqlInfoTmp, new Object[]{});
								if(in<=0){
									System.out.println("清空临时表备份失败！！");
								}
							}
						}
					}catch (Exception e) {
						e.printStackTrace();
						System.out.println(" 清空保养预测临时表时发生异常："+e);
						return false;
					} 
					
					
					
				}
				System.out.println("保养预测结束~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
				return true;
				}catch (Exception e) {
					e.printStackTrace();
					System.out.println(" 初始化保养预测信息表信息后，执行预测时发生异常："+e);
					return false;
				} 
			} else {
				System.out.println("保养预测结束~~~~~~初始化保养预测信息表信息-------失败！");
				return false;
				
			}
			
	} catch(Exception e) {
		e.printStackTrace();
		System.out.println(" 董少辉 类："+this.getClass().getName()+"" +
		" 方法:mtnForstShowTime 执行:车辆定时保养预测方法 发生异常");
		return false;
	} 
	}
	
	/**
	 * 查询保存了保养标准的设备型号下的所有设备
	 * @return
	 */
	public List<Map<String,Object>> getVehicleInfoListByStandard() {
		String sql = "select vvi.VehicleID,vvi.VehicleNumber,vvi.VehicleNo,vvi.VehicleTypeID from V_VehicleInfo vvi " +
				" where vvi.UsefulLife>=GETDATE() and Tmnl_SoftEdition is not null and vvi.VehicleTypeID in ("+
				"select MtnFS_VclT_ID from MtnForst_StandardNew where convert(varchar(10),MtnFS_Eff,126) <= getdate() " +
				"and convert(varchar(10),MtnFS_Exp,126)> getdate() group by MtnFS_VclT_ID)";
		List<Map<String,Object>> vehicleInfoList = baseDAO.execQuery(sql, new Object[]{});
		return vehicleInfoList;
		
	}
	
	/**
	 * 初始化保养预测信息
	 * @param DataList
	 */
	public boolean initMtnFrost(List DataList){
		List<String> sql = new ArrayList<String>();
		for(int i = 0; i<DataList.size();i++){
			 sql.add("insert into MtnForst_InfoNew_Tmp (MtnFN_MsgTime,MtnFN_VclID,MtnFN_VclT_ID,MtnFN_DatePre)" +
					     "select getdate(),vvi.VehicleID,vvi.VehicleTypeID,'"+DataList.get(i)+"' from V_VehicleInfo vvi " +
						 "where vvi.UsefulLife>=GETDATE() and Tmnl_SoftEdition is not null and vvi.VehicleTypeID in (" +
						 "select MtnFS_VclT_ID from MtnForst_StandardNew group by MtnFS_VclT_ID);");
			 if(i%5==0){
				 tranDAO.batch(sql);
				 sql = new ArrayList<String>();
			 }
		}
		return tranDAO.batch(sql);
	}
	
	/**
	 *方法说明： 查询保养参数信息
	 * fujichaun
	 * 2014/05/24
	 */
	public Map<String,Object> getSys_ParmConfig(){
		String sql = "SELECT SysPC_ID,SysPC_MtnInHours,SysPC_MtnInKm,SysPC_DayMinMile,SysPC_DayMinWorkHours FROM Sys_ParmConfig";
		return baseDAO.execQueryOne(sql, new Object[]{});
	}
	
	/**
	 *方法说明： 获取每台设备前30天内平均行驶里程
	 * fujichaun
	 * 2014/05/24
	 */
	public Map<String,Object> getPerDayMile(List<Map<String,Object>> VehicleInfoList,String yesDate,String yesDateTh,Map<String,Object> sysParam){
		//将设备ID拼接
		StringBuffer vclIdArr = new StringBuffer();
		String vclIDs = "";
		if(VehicleInfoList!=null && VehicleInfoList.size()>0){
			for(int i = 0;i<VehicleInfoList.size();i++){
				vclIdArr.append(MapGetter.getString(VehicleInfoList.get(i), "VehicleID"));
				if(i != VehicleInfoList.size()-1){
					vclIdArr.append(",");
				}
			}
			vclIDs = vclIdArr.toString();
		}
		
		int[] months= DateRegUtil.getMonthSql(yesDateTh, yesDate);
		String Msql="";
		for(int i=0;i<months.length;i++){
			Msql=Msql+"select msgess_vcl_id as msgstp_vclid,"+
                       "msgess_msgtime as msgstp_stattime,"+
					"MsgESS_iWork,"+
					"MsgESS_tWork,"+
					"MsgESS_iOilCons,"+
					"MsgESS_tOilCons,"+
					"MsgESS_iRunKmECM,"+
					"MsgESS_tRunKmECM,"+
					"MsgESS_iRunKmGPS,"+
					"MsgESS_tRunKmGPS,"+
					"MsgESS_iRunKmExact,"+
					"MsgESS_tRunKmExact,"+
					"MsgESS_iRunKmExact_ECM,"+
					"MsgESS_tRunKmExact_ECM,"+
					"MsgESS_iRunKmECU,"+
					"MsgESS_tRunKmECU,"+
					"MsgESS_iIdleWorkTime_PGN,"+
					"MsgESS_tIdleWorkTime_PGN,"+
					"MsgESS_iIdleWorkTime_UDS,"+
					"MsgESS_tIdleWorkTime_UDS,"+
					"MsgESS_iUreaConsumption,"+
					"MsgESS_tUreaConsumption "+
					"from "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+months[i], "3", null)+" union all ";
		}
		
		Msql=Msql.substring(0, Msql.length()-10);
		String sql = "select tmp.msgstp_vclid,avg(rumKm) avgKm from (select MsgSTP_VclID,MsgSTP_StatTime," +
				"rumKm = CASE vehicleRumKmId when 1 then MsgESS_iRunKmExact when 2 then MsgESS_iRunKmExact_ECM " +
				"when 3 then MsgESS_iRunKmECM when 4 then MsgESS_iRunKmECU when 5 then MsgESS_iRunKmGPS else MsgESS_iRunKmExact " +
//				"end  from ("+Msql+") ml Left join v_vehicleInfo on MsgSTP_VclID = vehicleId)tmp where tmp.msgstp_vclid in ("+vclIDs+")" +
				"end  from ("+Msql+") ml Left join v_vehicleInfo on MsgSTP_VclID = vehicleId)tmp where 1=1 " +
				"and MsgSTP_StatTime>='"+yesDateTh+"' and MsgSTP_StatTime<='"+yesDate+"' and rumKm > "+MapGetter.getString(sysParam, "SysPC_DayMinMile")+" group by msgstp_vclid";
		List<Map<String,Object>> runKmMapList = baseDAO.execQuery(sql, new Object[]{});
		Map<String,Object> runKmMap = new HashMap<String, Object>();
		//转换为MAP("设备号"，平均里程)形式，Message_Stat_TimingParam表中没有统计的设备，设为空
		if(VehicleInfoList!=null && VehicleInfoList.size()>0){
			for(int i = 0;i<VehicleInfoList.size();i++){
				if(runKmMapList!=null && runKmMapList.size()>0){
					int flag = 0;
					for(int j = 0;j<runKmMapList.size();j++){
							if(MapGetter.getString(VehicleInfoList.get(i), "VehicleID").equals(MapGetter.getString(runKmMapList.get(j), "MsgSTP_VclID"))){
								runKmMap.put(VehicleInfoList.get(i).get("VehicleID").toString(), runKmMapList.get(j).get("avgKm"));
								flag = 1;
							}
						}
					if(flag == 0){
						runKmMap.put(VehicleInfoList.get(i).get("VehicleID").toString(), "");
					}
					}
				}
			}
		
		return runKmMap;
	}
	
	/**
	 *方法说明： 获取每台设备前30天内平均工作小时
	 * fujichaun
	 * 2014/05/24
	 */
	public Map<String,Object> getPerDayWorkHour(List<Map<String,Object>> VehicleInfoList,String yesDate,String yesDateTh,Map<String,Object> sysParam){
		//将设备ID拼接
		StringBuffer vclIdArr = new StringBuffer();
		String vclIDs = "";
		if(VehicleInfoList!=null && VehicleInfoList.size()>0){
			for(int i = 0;i<VehicleInfoList.size();i++){
				vclIdArr.append(MapGetter.getString(VehicleInfoList.get(i), "VehicleID"));
				if(i != VehicleInfoList.size()-1){
					vclIdArr.append(",");
				}
			}
			vclIDs = vclIdArr.toString();
		}
		int[] months= DateRegUtil.getMonthSql(yesDateTh, yesDate);
		String Msql="";
		for(int i=0;i<months.length;i++){
			Msql=Msql+"select msgess_vcl_id as MsgSTP_VclID,"+
                " msgess_msgtime as msgstp_stattime,"+
                " msgess_iwork as MsgSTP_iEWorkHours "+
					"from "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+months[i], "3", null)+" union all ";
		}
		Msql=Msql.substring(0, Msql.length()-10);
		String sql = "select MsgSTP_VclID,avg(MsgSTP_iEWorkHours) avgWorkHour from ("+Msql+") ml where 1=1 " +
				"and msgstp_stattime>='"+yesDateTh+"' and msgstp_stattime<='"+yesDate+"' and MsgSTP_iEWorkHours > "+MapGetter.getString(sysParam, "SysPC_DayMinWorkHours")+" group by MsgSTP_VclID";
		List<Map<String,Object>> runWorkHourMapList = baseDAO.execQuery(sql, new Object[]{});
		Map<String,Object> runKmMap = new HashMap<String, Object>();
		//转换为MAP("设备号"，平均工作小时)形式，Message_Stat_TimingParam表中没有统计的设备，设为空
		if(VehicleInfoList!=null && VehicleInfoList.size()>0){
			for(int i = 0;i<VehicleInfoList.size();i++){
				if(runWorkHourMapList!=null && runWorkHourMapList.size()>0){
					int flag = 0;
					for(int j = 0;j<runWorkHourMapList.size();j++){
							if(MapGetter.getString(VehicleInfoList.get(i), "VehicleID").equals(MapGetter.getString(runWorkHourMapList.get(j),"MsgSTP_VclID"))){
								runKmMap.put(VehicleInfoList.get(i).get("VehicleID").toString(), runWorkHourMapList.get(j).get("avgWorkHour"));
								flag = 1;
							}
						}
					if(flag == 0){
						runKmMap.put(VehicleInfoList.get(i).get("VehicleID").toString(), "");
					}
					}
				}
			}
		
		return runKmMap;
	}
	/**
	 * 获取设定了固定时间间隔保养方式的设备最近一次的提醒日期
	 * @param VehicleInfoList
	 * @return
	 */
	public Map<String,Object> getvehicleTipDateLast(List<Map<String,Object>> VehicleInfoList){
		StringBuffer vclIdArr = new StringBuffer();
		String vclIDs = "";
		if(VehicleInfoList!=null && VehicleInfoList.size()>0){
			for(int i = 0;i<VehicleInfoList.size();i++){
				vclIdArr.append(MapGetter.getString(VehicleInfoList.get(i), "VehicleID"));
				if(i != VehicleInfoList.size()-1){
					vclIdArr.append(",");
				}
			}
			vclIDs = vclIdArr.toString();
		}
//		String sql = "select max(MtnAL_AlarmDate) MtnAL_AlarmDate,MtnAL_VclID from Mtn_Alarm_InfoList where MtnAL_AlarmType = 3 and MtnAL_VclID in ("+vclIDs+") group by MtnAL_VclID";
		String sql = "select max(MtnAL_AlarmDate) MtnAL_AlarmDate,MtnAL_VclID from Mtn_Alarm_InfoList where MtnAL_AlarmType = 3 group by MtnAL_VclID";
		List<Map<String,Object>> dateLastMapList = baseDAO.execQuery(sql, new Object[]{});
		Map<String,Object> dateMap = new HashMap<String, Object>();
		//转换为MAP("设备号"，最近一次提醒日期)形式，Mtn_Alarm_InfoList表中没有统计的设备，设为空
		if(VehicleInfoList!=null && VehicleInfoList.size()>0){
			for(int i = 0;i<VehicleInfoList.size();i++){
				if(dateLastMapList!=null && dateLastMapList.size()>0){
					int flag = 0;
					for(int j = 0;j<dateLastMapList.size();j++){
							if(VehicleInfoList.get(i).get("VehicleID").equals(dateLastMapList.get(j).get("MtnAL_VclID"))){
								dateMap.put(VehicleInfoList.get(i).get("VehicleID").toString(), dateLastMapList.get(j).get("MtnAL_AlarmDate"));
								flag = 1;
							}
						}
					if(flag == 0){
						dateMap.put(VehicleInfoList.get(i).get("VehicleID").toString(), "");
					}
					}
				}
			}
		return dateMap;
		
	}
	/**
	 * 获取设定了保养标准的设备的全部信息集合
	 * @return
	 */
	public List<Map<String,Object>> getVehicleAllInfoList(String yesDay) {
		String time=yesDay.substring(0, 7).replace("-", "");
		String sql = "select VehicleID,vehicleNumber,trunKm = CASE vehicleRumKmId "+
					"when 1 then MsgESS_tRunKmExact "+
					"when 2 then MsgESS_tRunKmExact_ECM "+
					"when 3 then MsgESS_tRunKmECM "+ 
					"when 4 then MsgESS_tRunKmECU "+ 
					"when 5 then MsgESS_tRunKmGPS "+ 
					"else MsgESS_tRunKmExact end , "+
					"MsgESS_tWork as MsgSTP_tEWorkHours, MtnFS_MtnType, MtnFS_MtnIn, MtnFS_MtnOut,MaintfixeStartDate from V_VehicleInfo "+
					"inner join MtnForst_StandardNew on MtnFS_VclT_ID = VehicleTypeID "+
					"left join "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+time, "3", null)+" on VehicleID = MsgESS_Vcl_ID and MsgESS_MsgTime = '"+yesDay+"' "+
					"where UsefulLife>=GETDATE()  and Tmnl_SoftEdition is not null and "+
					"convert(varchar(10),MtnFS_Eff,126) <= getdate() and convert(varchar(10),MtnFS_Exp,126)> getdate()";
		 return baseDAO.execQuery(sql, new Object[]{});
		
	}
	
	/**
	 * 按公里数进行保养
	 * @param veMap
	 * @param vehiclePerDayMileMap
	 * @param DataList
	 * @return
	 */
	public boolean frostByKm(Map<String,Object> veMap,Map<String,Object> vehiclePerDayMileMap,List DataList){
		MyConnectDSTransDAO myConnectDSTransDAO=new MyConnectDSTransDAO();
		//预测SQL
//		StringBuffer sb = new StringBuffer();
		List<String> sb = new ArrayList<String>();
		if(vehiclePerDayMileMap!=null && vehiclePerDayMileMap.size()>0){
			//取出该设备的平均行驶里程
			double perMile = MapGetter.getDouble(vehiclePerDayMileMap, MapGetter.getString(veMap, "VehicleID"));
			//昨日的累积里程值
			String toKmMiles = MapGetter.getString(veMap, "trunKm");
			double toKmMile = 0.0;
			if(StringUtil.isValid(toKmMiles)){
				toKmMile = Double.parseDouble(toKmMiles);
			}
			//保内间隔公里数
			double mtnInMile = MapGetter.getDouble(veMap, "MtnFS_MtnIn");
			//保外间隔公里数
			double mtnOutMile = MapGetter.getDouble(veMap, "MtnFS_MtnOut");
			double frostStandard = 0;
			//基础判断值
			double mtnValue = 0;
			if(perMile>0){
				//根据累计值和保养标准判断保内和保外
				if(toKmMile<=mtnInMile){
					if(mtnInMile>0){
						//保内基础判断值
						mtnValue = Math.floor((toKmMile/mtnInMile));
						frostStandard = mtnInMile;
					}
				} else {
					if(mtnOutMile>0){
						//保内基础判断值
						mtnValue =Math.floor((toKmMile/mtnOutMile));
						frostStandard = mtnOutMile;
					}
				}
				for(int i = 0;i<DataList.size();i++){
					double mtnValueThis = 0;
					//每天的更新累计值
					toKmMile = toKmMile+perMile;
					if(frostStandard>0){
						//每天的保内判断值
						mtnValueThis = Math.floor((toKmMile/frostStandard));
					}
					//本次的判断值大于上次的判断值，则进行保养预测
					if(mtnValueThis>mtnValue){
						sb.add(" update MtnForst_InfoNew_Tmp set MtnFN_IsKmForst = 1,MtnFN_KmPre = "+mtnValueThis*frostStandard+" where MtnFN_VclID = "+MapGetter.getString(veMap, "VehicleID")+" and MtnFN_DatePre = '"+DataList.get(i)+"';");
						logdata.info("按公里数："+sb);
					}
					mtnValue = mtnValueThis;
				}
				if(sb.size()>0){
					try{
						boolean flag = myConnectDSTransDAO.batch(sb);
						if(!flag){
							System.out.println("按公里数：执行更新预测信息表----失败！！");
						}
					}catch(Exception e){
						System.out.println("按公里数：执行更新预测信息表----失败！！异常"+e);
					}
					
				}
			}
			return true;
		} else {
			return false;
		}
		
	}
	
	/**
	 * 按工作小时数进行保养
	 * @param veMap
	 * @param vehiclePerDayWorkHourMap
	 * @param DataList
	 * @return
	 */
	public boolean frostByWorkHour(Map<String,Object> veMap,Map<String,Object> vehiclePerDayWorkHourMap,List DataList){
		MyConnectDSTransDAO myConnectDSTransDAO=new MyConnectDSTransDAO();
		//预测SQL
//		StringBuffer sb = new StringBuffer();
		List<String> sb = new ArrayList<String>();
		if(vehiclePerDayWorkHourMap!=null && vehiclePerDayWorkHourMap.size()>0){
			//取出该设备的平均工作小时数
			double perWorkHour = MapGetter.getDouble(vehiclePerDayWorkHourMap, MapGetter.getString(veMap, "VehicleID"));
			//昨日的累积工作小时数
			double toWorkHour = MapGetter.getDouble(veMap, "MsgSTP_tEWorkHours");
			//保内间隔工作小时数
			double mtnInMile = MapGetter.getDouble(veMap, "MtnFS_MtnIn");
			//保外间隔工作小时数
			double mtnOutMile = MapGetter.getDouble(veMap, "MtnFS_MtnOut");
			double frostStandard = 0;
			//基础判断值
			double mtnValue = 0;
			if(perWorkHour>0){
				//根据累计值和保养标准判断保内和保外
				if(toWorkHour<=mtnInMile){
					if(mtnInMile>0){
						//保内基础判断值
						mtnValue = Math.floor((toWorkHour/mtnInMile));
						frostStandard = mtnInMile;
					}
				} else {
					if(mtnOutMile>0){
						//保外基础判断值
						mtnValue =Math.floor((toWorkHour/mtnOutMile));
						frostStandard = mtnOutMile;
					}
				}
				for(int i = 0;i<DataList.size();i++){
					double mtnValueThis = 0;
					//每天的更新累计值
					toWorkHour = toWorkHour+perWorkHour;
						if(frostStandard>0){
							//每天的判断值
							mtnValueThis = Math.floor((toWorkHour/frostStandard));
						}
					//本次的判断值大于上次的判断值，则进行保养预测
					if(mtnValueThis>mtnValue){
						sb.add(" update MtnForst_InfoNew_Tmp set MtnFN_IsWorkForst = 1,MtnFN_WorkPre = "+mtnValueThis*frostStandard+" where MtnFN_VclID = "+MapGetter.getString(veMap, "VehicleID")+" and MtnFN_DatePre = '"+DataList.get(i)+"';");
					}
					mtnValue = mtnValueThis;
				}
				logdata.info("按工作小时数："+sb);
				if(sb.size()>0){
					try{
						boolean flag = myConnectDSTransDAO.batch(sb);
						if(!flag){
							System.out.println("按工作小时数：执行更新预测信息表----失败！！");
						}
					}catch(Exception e){
						System.out.println("按工作小时数：执行更新预测信息表----失败！！异常"+e);
					}
					
				}
				
			}
			return true;
		} else {
			return false;
		}
		
	}
	/**
	 * 按固定时间间隔进行保养
	 * @param veMap
	 * @param vehicleDateMap
	 * @param DataList
	 * @return
	 * @throws ParseException
	 */
	public boolean frostByDate(Map<String,Object> veMap,Map<String,Object> vehicleDateMap,List DataList) throws ParseException{
		MyConnectDSTransDAO myConnectDSTransDAO=new MyConnectDSTransDAO();
		//预测SQL
		List<String> sb = new ArrayList<String>();
		String beginDate = "";
		String lastTipDate = "";
		Date d1 = new Date();
		Date d2 = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		//预测结束日期
		Date endDate =sdf.parse(DataList.get(DataList.size()-1).toString());
		d2 = sdf.parse(MapGetter.getString(veMap, "MaintfixeStartDate"));
		//保内间隔天数
		int mtnDays = 0;
		String mtnDayst = MapGetter.getString(veMap, "MtnFS_MtnIn");
		double mtnDaysd = Double.parseDouble(mtnDayst);
		mtnDays = (int)mtnDaysd;
		if(vehicleDateMap!=null &&vehicleDateMap.size()>0){
			lastTipDate = MapGetter.getString(vehicleDateMap, "MtnAL_AlarmDate");
			if(StringUtil.isValid(lastTipDate)){
				d1 = sdf.parse(lastTipDate);
			}
			if(!StringUtil.isValid(lastTipDate) || d2.after(d1)){
				beginDate = MapGetter.getString(veMap, "MaintfixeStartDate");
			} else {
				beginDate = lastTipDate;
			}
			
		} else {
			beginDate = MapGetter.getString(veMap, "MaintfixeStartDate");
		}
		int frostNum = 1;
		while(true){
			Calendar calBegin = Calendar.getInstance();
			calBegin.setTime(sdf.parse(beginDate));
			 calBegin.add(Calendar.DAY_OF_MONTH, mtnDays*frostNum);
			 //判断预测的日期是否在结束日期之前
			if(!calBegin.getTime().after(endDate)){
				frostNum++;
				//
				sb.add("update MtnForst_InfoNew_Tmp set MtnFN_IsGapForst = 1,MtnFN_GapPre = "+mtnDays+" where MtnFN_VclID = "+MapGetter.getString(veMap, "VehicleID")+" and MtnFN_DatePre = '"+sdf.format(calBegin.getTime())+"';");
				logdata.info("按固定时间间隔:"+sb);
			} else{
				break;
			}
		}
		if(sb.size()>0){
			try{
				boolean flag = myConnectDSTransDAO.batch(sb);
				sb = new ArrayList<String>();
				if(!flag){
					System.out.println("按固定时间间隔：执行更新预测信息表----失败！！");
				}
			}catch(Exception e){
				System.out.println("按固定时间间隔：执行更新预测信息表----失败！！异常"+e);
			}
			
		}
		return true;
		
	}
	
}